import { baseURL } from '@/config'
import { post } from '@/http/axios'
import { getToken } from '@/util/store'

export const downfile = (url, name) => {
  if (!url) return
  const a = document.createElement('a')
  name && (a.download = name)
  a.href = url
  a.target = '_blank'
  a.click()
}

export const fileurl = id =>
  id ? baseURL + '/exportFile?token=' + getToken() + '&id=' + id : ''

export const getQRCode = id =>
  id ? baseURL + '/showAssetQRCode?token=' + getToken() + '&id=' + id : ''

export const getImg = id =>
  id ? baseURL + '/getImg?token=' + getToken() + '&id=' + id : ''

export const upload = (...args) => post('/addFile', ...args)

export const getProcessNodeImg = id =>
  id
    ? baseURL + '/showWorkflowProcessDiagram?token=' + getToken() + '&id=' + id
    : ''

export const getProcessLeafImg = (id, flow_code) =>
  id && flow_code
    ? baseURL +
      '/showWorkflowNodeDiagram?token=' +
      getToken() +
      '&id=' +
      id +
      '&flow_code=' +
      flow_code
    : ''
